package model

import (
	"DouBan/utils"
	"gorm.io/gorm"
)

type Subscribe struct {
	Id          uint      `json:"id" gorm:"primaryKey;autoIncrement"`
	RentType    RentType  `json:"rent_type" gorm:"column:rent_type"`
	HouseType   HouseType `json:"house_type" gorm:"column:house_type"`
	UserId      uint      `json:"user_id" gorm:"column:user_id"`
	City        City      `json:"city" gorm:"city"`
	CreatedTime string    `json:"created_time" gorm:"column:created_time;type:varchar(20)"`
	UpdateTime  string    `json:"update_time" gorm:"column:update_time;type:varchar(20)"`
}

func (s Subscribe) TableName() string {
	return "subscribe"
}

func (s *Subscribe) BeforeSave(tx *gorm.DB) error {
	nowTimeStr := utils.GetNowTimeStr()
	if s.CreatedTime == "" {
		s.CreatedTime = nowTimeStr
	}
	s.UpdateTime = nowTimeStr
	return nil
}
